import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
// 引入element Plus
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src'),
        //设置文件路径别名
        '@view': resolve('src/renderer/src/view'),
        //设置路由路径别名
        '@router': resolve('src/renderer/src/router'),
        //设置pinia路径别名
        '@store': resolve('src/renderer/src/store'),
        //设置工具路径别名
        '@utils': resolve('src/renderer/src/utils'),
        //设置api路径别名
        '@api': resolve('src/renderer/src/api'),
        //设置api路径别名
        '@interface': resolve('src/renderer/src/interface'),
        //设置hook短路径
        '@hooks': resolve('src/renderer/src/hooks'),
        //设置layouot短路径
        '@layout': resolve('src/renderer/src/layout'),
        // 设置全局混入 在这里面更改完之后一定要重启
        '@mixins': resolve('src/renderer/src/mixins'),
        // 短路径
        '@components': resolve('src/renderer/src/components')
      }
    },

    css: {
      preprocessorOptions: {
        scss: {
          api: 'modern-compiler',
          silenceDeprecations: ['legacy-js-api']
        }
      }
    },
    // 配置代理解决跨域问题
    server: {
      proxy: {
        '/api': {
          target: 'http://uat.crm.xuexiluxian.cn',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
      vue()
    ]
  }
})
